// hyb_yl/mycenter/pages/Twitter/Twitter.js
var app = getApp()
var template = require('../../../../template/Twitter.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabBar:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    template.tabbar("tabBar", 0, this)
    // var id = options.id
    if(options.id==undefined){
      var id = wx.getStorageSync('twitterid')
    }else{
      var id = options.id
      wx.setStorageSync('twitterid', id)
    }
    //查询我是否存在上级
    app.util.request({
      url: 'entry/wxapp/tuike.myshangji',
      data: {
        id: id
      },
      success: function (res) {
        console.log(res)
        if (res.data == 0) {
          app.globalData.tkid = 0
        } else {
          app.globalData.tkid = res.data //上级id
        }
      }
    })
    this.setData({
      id: id
    })
    this.getTuikeinfo()
    this.getTuikedata()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  getTuikeinfo() {
    var that = this
    var id = that.data.id
    app.util.request({
      'url': 'entry/wxapp/index.tuikeinfo',
      data: {
        id: id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          info: res.data
        })
      }
    })
  },
  getTuikedata() {
    var that = this
    var id = that.data.id
    app.util.request({
      'url': 'entry/wxapp/index.tuikedata',
      data: {
        id: id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          count: res.data
        })
      }
    })
  },
  tkerweim() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/tuike.erweima',
      data: {
        id: that.data.id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          imgerweima: res.data,
          img_state: true
        })
      }
    })
  },
  close_ewm: function (e) {
    this.setData({
      img_state: false
    })
  },
  sava_btn: function (e) {
    var img = this.data.imgerweima
    wx.getImageInfo({
      src: img,
      success: res => {
        wx.saveImageToPhotosAlbum({
          filePath: res.path,
          success(result) {
            console.log(result)
          }
        })

      }
    })
  }

})